
library(foreign) # install these packages if you haven't already
library(ggplot2)
library(gridExtra)
library(grid)
library(lattice)
library(tidyverse)
library(maps)
library(usmap)
library(mapproj)
library(dplyr)
library(ggcorrplot)

setwd("") # set working directory

########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################### IN TEXT FIGURES ############################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################

################ FIGURE 1: we cannot share the data for Figure S21/S22 in the Supporting Information, because it includes lat/long files. As per our data availability statement provided to the journal at original submission, we cannot share identifying information.
#us_states <- map_data("state")

#state_full<-read.dta("") # data not included due to the inclusion of identifying information (i.e. lat/long codes)
#state_full2<-read.dta("") # data not included due to the inclusion of identifying information (i.e. lat/long codes)

#p <- ggplot(data = us_states,
   #         mapping = aes(x = long, y = lat, group = group)) 

#p1 <- p + geom_polygon(colour = "white", fill="grey60", size = 0.05) +  
#  coord_map(projection = "albers", lat0 = 39, lat1 = 45) + 
#  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
#        panel.background = element_blank(), axis.line = element_line(colour = "grey40")) + theme_void()  +
#  guides(fill=guide_legend(title=""))  +
#  theme(text = element_text(size=30)) +
#  scale_x_continuous(expand = c(0, 0)) +
#  scale_y_continuous(expand = c(0, 0))  


#p2 <- p1 +  geom_count(data=state_full2, aes(x = registrationaddresslongitude1, y = registrationaddresslatitude1, group="none"), 
 #                      size=6, alpha=0.4, colour="#1b7837") + 
#  geom_count(data=state_full, aes(x = registrationaddresslongitude1, y = registrationaddresslatitude1, group="none"), 
#             size=6, alpha=0.12, colour="#762a83")  

#p3 <- p2 + theme(legend.position="top") +   
#  annotate("text", x = -73.3 , y = 29, label="Responded to white, but not black sender", colour = "#762a83", size=11, fontface="bold") + 
#  annotate("text", x = -73, y = 30, label="Responded to black, but not white sender", colour = "#1b7837", size=11, fontface="bold") 

#p3

#ggsave(p3, file="public_dot_map.pdf", width=19, height=10, scale=2, dpi=300)

################# FIGURE 2, LEFT PANEL


diffdiffall<-read.dta("overall_effects_concordance_no_interact.dta")
attach(diffdiffall) 

  color.names <- c("#1b7837", "#762a83")
  
plot1<-ggplot(diffdiffall, aes(y=coef_base,  x=reorder(group, model_num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, aes(colour=group), size=12) +
  geom_errorbar(aes(ymin=coef_base-1.96*stderr_base, ymax=coef_base+1.96*stderr_base, colour=group), width=0, size=2) +
  geom_errorbar(aes(ymin=coef_base-1.64*stderr_base, ymax=coef_base+1.64*stderr_base, colour=group), width=0, size=4) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="", y="Effect of a Black Request on Response Rate", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_y_continuous(limits=c(-.25, .25)) + 
  theme(text = element_text(size=22)) +
  coord_flip() + theme(legend.position="none") +
  scale_colour_manual(values=color.names) +
  annotate("text", x = 2.4 , y = -0.13, label="Discrimination Against Blacks", colour = "grey60", size=6, fontface="bold") +
  annotate("text", x = 2.4 , y = 0.13, label="Discrimination Against Whites", colour = "grey60", size=6, fontface="bold") 
  
plot1
ggsave(plot1, file="main_effect.png", width=5, height=3, scale=2)

################## FIGURE 2, RIGHT PANEL
all3<-read.dta("public permute clean.dta")
all4<-read.dta("elected officials permute clean.dta")

attach(all3) 

plot1<- ggplot(all3, aes(b_blacktr)) +
  geom_density(data=all3, alpha = 0.6, fill = "#762a83", colour = "#762a83", ) + 
  geom_density(data=all4, alpha = 0.6, fill = "#1b7837", colour = "#1b7837", ) + 
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="Permutation Effect Estimates", y="Density", title="") +
  theme(text = element_text(size=40)) + 
  theme(legend.position="none") +
  geom_vline(aes(xintercept=-.096581), colour="#762a83", linetype="dashed", size=2, alpha = 0.6) +
  geom_vline(aes(xintercept=-.0593825 ), colour="#1b7837", linetype="dashed", size=2, alpha = 0.6) +
  annotate("text", x = -0.09 , y = 10, label="Public Effect", colour = "#762a83", size=11, fontface="bold", angle = 90, alpha = 0.6) +
  annotate("text", x = -0.053 , y = 10, label="Elected Official Effect", colour = "#1b7837", size=11, fontface="bold", angle = 90, alpha = 0.6) + 
  annotate("text", x = -0.11 , y = 2.8, label="0%", colour = "#762a83", size=10, fontface="bold", alpha = 0.6) + 
  annotate("text", x = -0.074 , y = 2.8, label="4.5%", colour = "#1b7837", size=10, fontface="bold", alpha = 0.6) + 
  scale_x_continuous(limits=c(-.2, .2))

plot1

ggsave(plot1, file="permute_public_elected_dist.pdf", width=8, height=6, scale=2)

################ FIGURE 3



diffdiffall<-read.dta("overall_effects_by_recipient_race_old.dta")
attach(diffdiffall) 

plot1<-ggplot(diffdiffall, aes(y=coef_base,  x=reorder(group, model_num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, colour="black", aes(size=N)) +
  geom_errorbar(aes(ymin=coef_base-1.96*stderr_base, ymax=coef_base+1.96*stderr_base), colour="black", width=0, size=1) +
  geom_errorbar(aes(ymin=coef_base-1.64*stderr_base, ymax=coef_base+1.64*stderr_base), colour="black", width=0, size=2) +
  theme_bw() + theme(axis.line = element_line(colour = "black"),
                     panel.grid.major = element_blank(),
                     panel.grid.minor = element_blank(),
                     panel.border = element_blank(),
                     panel.background = element_blank()) +
  labs(x="Recipient Race/Ethnicity", y="Effect of a Black Request on Response Rate", title="") +
  scale_y_continuous(limits=c(-.35, .17)) + 
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=15)) + theme(legend.position="none") +
  scale_size(range = c(4, 12)) +
  coord_flip() +
  labs(size = "Sample Size") 

plot1
ggsave(plot1, file="public_effect_by_recipient_race_for_concordance.png", width=4, height=4, scale=2)

################# FIGURE 4


diffdiffall<-read.dta("by_political_party.dta")
attach(diffdiffall) 

color.names <- c("blue", "darkgreen", "red")

pd <- position_dodge(width=0.62)  

plot1<-ggplot(diffdiffall, aes(y=coef_base,  x=reorder(subgroup, model_num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, aes(colour=subgroup), size=12, position = pd) +
  geom_errorbar(aes(ymin=coef_base-1.96*stderr_base, ymax=coef_base+1.96*stderr_base, colour=subgroup), width=0, size=2, position = pd) +
  geom_errorbar(aes(ymin=coef_base-1.64*stderr_base, ymax=coef_base+1.64*stderr_base, colour=subgroup), width=0, size=4, position = pd) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="", y="Difference in Discriminatory Effects by Political Party", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=22)) +
  scale_y_continuous(limits=c(-.25, .25)) + 
  coord_flip() + theme(legend.position="none") +
  scale_colour_manual(values=color.names) 


plot1
ggsave(plot1, file="effects_by_party.png", width=5, height=3, scale=2)


########## FIGURE 5, FIRST PANEL
us_states <- map_data("state")



map2000<-read.dta("public discrimination by state.dta")

state_full <- left_join(us_states, map2000, by = "region")

attach(map2000)
n=6
breaks = seq(min(coef), max(coef), length.out = n)

p <- ggplot(data = state_full,
            mapping = aes(x = long, y = lat,
                          fill = coef, group = group)) + scale_colour_gradient(low = "black", high = "white")

p1 <- p + geom_polygon(color = "gray90", size = 0.05) +  coord_map(projection = "albers", lat0 = 39, lat1 = 45) + 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), axis.line = element_line(colour = "black")) + theme_void() + theme(legend.position="bottom") +
  guides(fill=guide_legend(title=""))  +
  theme(text = element_text(size=30)) 

p2 <- p1 + scale_fill_gradient(low="grey10", high="grey50",
                               breaks=breaks, labels = scales::number_format(accuracy = 0.001, decimal.mark = '.')) +
  labs(caption = "Black = More Discrimination Towards Blacks") +
  scale_x_continuous(expand = c(0, 0)) +
  scale_y_continuous(expand = c(0, 0))  +
  annotate("text", x = -59 , y = 44, label="Most Discrimination in Study", colour = "black", size=6, fontface="bold") +
  annotate("text", x = -65 , y = 43.5, label="1. OK", colour = "black", size=6) +
  annotate("text", x = -65.7 , y = 42.5, label="2. IA", colour = "black", size=6) +
  annotate("text", x = -65.9 , y = 41.5, label="3. UT", colour = "black", size=6) +
  annotate("text", x = -66.4 , y = 40.5, label="4. PA", colour = "black", size=6) +
  annotate("text", x = -66.7 , y = 39.5, label="5. TN", colour = "black", size=6) +
  annotate("text", x = -67.0 , y = 38.5, label="6. NM", colour = "black", size=6) +
  annotate("text", x = -67.7 , y = 37.5, label="7. RI", colour = "black", size=6) +
  annotate("text", x = -67.9 , y = 36.5, label="8. AK", colour = "black", size=6) +
  annotate("text", x = -68.5 , y = 35.5, label="9. IL", colour = "black", size=6) +
  annotate("text", x = -68.8 , y = 34.5, label="10. MA", colour = "black", size=6) +
  annotate("text", x = -69.1 , y = 33.5, label="...", colour = "black", size=6) +
  annotate("text", x = -69.4 , y = 32.5, label="41. CO", colour = "black", size=6) +
  annotate("text", x = -69.8 , y = 31.5, label="42. LA", colour = "black", size=6) +
  annotate("text", x = -70 , y = 30.5, label="43. NC", colour = "black", size=6) +
  annotate("text", x = -70.4 , y = 29.5, label="44. WI", colour = "black", size=6) +
  annotate("text", x = -70.6 , y = 28.5, label="45. NY", colour = "black", size=6) +
  annotate("text", x = -70.8 , y = 27.5, label="46. OR", colour = "black", size=6) +
  
  annotate("text", x = -71.1 , y = 26.5, label="47. AR", colour = "black", size=6) +
  annotate("text", x = -71.35 , y = 25.5, label="48. DE", colour = "black", size=6) +
  annotate("text", x = -71.6 , y = 24.5, label="49. NV", colour = "black", size=6) +
  annotate("text", x = -72 , y = 23.5, label="50. ID", colour = "black", size=6) 

p2

ggsave(p2, file="public_by_state_with_list.pdf", width=10, height=5, scale=2, dpi = 300)


############# FIGURE 5, SECOND PANEL
us_states <- map_data("state")



map2000<-read.dta("elected discrimination by state.dta")

state_full <- left_join(us_states, map2000, by = "region")

attach(map2000)

n=6
breaks = seq(min(coef), max(coef), length.out = n)

p <- ggplot(data = state_full,
            mapping = aes(x = long, y = lat,
                          fill = coef, group = group)) + scale_colour_gradient(low = "black", high = "white")

p1 <- p + geom_polygon(color = "gray90", size = 0.05) +  coord_map(projection = "albers", lat0 = 39, lat1 = 45) + 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), axis.line = element_line(colour = "black")) + theme_void() + theme(legend.position="bottom") +
  guides(fill=guide_legend(title=""))  +
  theme(text = element_text(size=30)) 

p2 <- p1 + scale_fill_gradient(low="grey10", high="grey50",
                               breaks=breaks, labels = scales::number_format(accuracy = 0.001, decimal.mark = '.')) +
  scale_x_continuous(expand = c(0, 0)) +
  scale_y_continuous(expand = c(0, 0)) +
  labs(caption = "Black = More Discrimination Towards Blacks") +
  annotate("text", x = -59 , y = 44, label="Most Discrimination in Study", colour = "black", size=6, fontface="bold") +
  annotate("text", x = -65 , y = 43.5, label="1. NH", colour = "black", size=6) +
  annotate("text", x = -65.4 , y = 42.5, label="2. SC", colour = "black", size=6) +
  annotate("text", x = -66.1 , y = 41.5, label="3. IN", colour = "black", size=6) +
  annotate("text", x = -66.2 , y = 40.5, label="4. WV", colour = "black", size=6) +
  annotate("text", x = -66.7 , y = 39.5, label="5. ME", colour = "black", size=6) +
  annotate("text", x = -67.2 , y = 38.5, label="6. SD", colour = "black", size=6) +
  annotate("text", x = -67.5 , y = 37.5, label="7. NC", colour = "black", size=6) +
  annotate("text", x = -68.1 , y = 36.5, label="8. HI", colour = "black", size=6) +
  annotate("text", x = -68.5 , y = 35.5, label="9. RI", colour = "black", size=6) +
  annotate("text", x = -68.8 , y = 34.5, label="10. TN", colour = "black", size=6) +
  annotate("text", x = -69.1 , y = 33.5, label="...", colour = "black", size=6) +
  annotate("text", x = -69.4 , y = 32.5, label="41. MO", colour = "black", size=6) +
  annotate("text", x = -69.8 , y = 31.5, label="42. AK", colour = "black", size=6) +
  annotate("text", x = -70 , y = 30.5, label="43. AR", colour = "black", size=6) +
  annotate("text", x = -70.5 , y = 29.5, label="44. ID", colour = "black", size=6) +
  annotate("text", x = -70.65 , y = 28.5, label="45. FL", colour = "black", size=6) +
  annotate("text", x = -70.8 , y = 27.5, label="46. CT", colour = "black", size=6) +
  
  annotate("text", x = -71.0 , y = 26.5, label="47. GA", colour = "black", size=6) +
  annotate("text", x = -71.15 , y = 25.5, label="48. MA", colour = "black", size=6) +
  annotate("text", x = -71.4 , y = 24.5, label="49. OK", colour = "black", size=6) +
  annotate("text", x = -71.8 , y = 23.5, label="50. DE", colour = "black", size=6) 

ggsave(p2, file="elected_official_by_state.pdf", width=10, height=5, scale=2, dpi = 300)

############# FIGURE 5, THIRD PANEL

us_states <- map_data("state")



map2000<-read.dta("interaction discrimination by state.dta")

state_full <- left_join(us_states, map2000, by = "region")

p <- ggplot(data = state_full,
            mapping = aes(x = long, y = lat,
                          fill = coef, group = group)) + scale_colour_gradient(low = "#9970ab", high = "#5aae61")

p1 <- p + geom_polygon(color = "gray90", size = 0.05) +  coord_map(projection = "albers", lat0 = 39, lat1 = 45) + 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), axis.line = element_line(colour = "black")) + 
  theme_void() + theme(legend.position="bottom") +
  guides(fill=guide_legend(title=""))  +
  theme(text = element_text(size=30)) +
  scale_x_continuous(expand = c(0, 0)) +
  scale_y_continuous(expand = c(0, 0)) +
  annotate("text", x = -59 , y = 42, label="1. NH", colour = "#9970ab", size=6, fontface="bold") +
  annotate("text", x = -59.6 , y = 41.3, label="2. IN", colour = "#9970ab", size=6, fontface="bold") +
  annotate("text", x = -59.7 , y = 40.5, label="3. WV", colour = "#9970ab", size=6, fontface="bold") +
  annotate("text", x = -60.22 , y = 39.8, label="4. SC", colour = "#9970ab", size=6, fontface="bold") +
  annotate("text", x = -60.6 , y = 39, label="5. NC", colour = "#9970ab", size=6, fontface="bold") +
  annotate("text", x = -60.9 , y = 38.2, label="6. ME", colour = "#9970ab", size=6, fontface="bold") +
  annotate("text", x = -61.3 , y = 37.6, label="7. SD", colour = "#9970ab", size=6, fontface="bold") +
  annotate("text", x = -61.7 , y = 37, label="8. HI", colour = "#9970ab", size=6, fontface="bold") +
  annotate("text", x = -61.8 , y = 36.4, label="9. CO", colour = "#9970ab", size=6, fontface="bold") +
  annotate("text", x = -62.3 , y = 35.8, label="10. OR", colour = "#9970ab", size=6, fontface="bold") +
  
  annotate("text", x = -62.5 , y = 35.2, label="...", colour = "black", size=6) +
  
  annotate("text", x = -62.95 , y = 34.4, label="41. MT", colour = "#5aae61", size=6, fontface="bold") +
  annotate("text", x = -63.25 , y = 33.8, label="42. NE", colour = "#5aae61", size=6, fontface="bold") +
  annotate("text", x = -63.6 , y = 33, label="43. AK", colour = "#5aae61", size=6, fontface="bold") +
  annotate("text", x = -64.1 , y = 32.3, label="44. IA", colour = "#5aae61", size=6, fontface="bold") +
  annotate("text", x = -64.3 , y = 31.6, label="45. FL", colour = "#5aae61", size=6, fontface="bold") +
  annotate("text", x = -64.6 , y = 31, label="46. CT", colour = "#5aae61", size=6, fontface="bold")  +
  annotate("text", x = -64.8 , y = 30.3, label="47. GA", colour = "#5aae61", size=6, fontface="bold") +
  annotate("text", x = -65 , y = 29.6, label="48. MA", colour = "#5aae61", size=6, fontface="bold") +
  annotate("text", x = -65.3 , y = 29, label="49. DE", colour = "#5aae61", size=6, fontface="bold") +
  annotate("text", x = -65.6 , y = 28.3, label="50. OK", colour = "#5aae61", size=6, fontface="bold")


p2 <- p1 + scale_fill_gradient(low="#9970ab", high="#5aae61", limits=c(-0.023, 0.032)) +
  annotate("text", x = -59 , y = 44, label="Elected Officials Discriminate More", colour = "#9970ab", size=6, fontface="bold") + 
  annotate("text", x = -59, y = 43, label="Public Discriminates More", colour = "#5aae61", size=6, fontface="bold") 

p2

ggsave(p2, file="interaction_by_state.pdf", width=10, height=5, scale=2, dpi = 300)

########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################### APPENDIX FIGURES ###########################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################
########################################################################################################################################


################### FIGURE S1


diffdiffall<-read.csv("study_comparison_with_meta.csv")
attach(diffdiffall) 

color.names<-c("grey55", "black")
xaxislabels <- c("Meta Analysis \n [Random Effects]", "Meta Analysis \n [Unweighted]","Meta Analysis \n [Weighted]",
                 "Hughes et al. \n (2019)", 
                 "Gell-Redman et al. \n (2018)", 
                 "Butler \n (2014)", 
                 "Butler and Crabtree \n (2017)",
                 "Einstein and Glick \n (2017)",
                 "Broockman and Butler \n (2011)")

plot1<-ggplot(diffdiffall, aes(y=late,  x=reorder(study, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, aes(colour=factor(color), size=n, shape=factor(color))) +
  geom_errorbar(aes(ymin=late-1.96*se, ymax=late+1.96*se, colour=factor(color)), width=0, size=1) +
  geom_errorbar(aes(ymin=late-1.64*se, ymax=late+1.64*se, colour=factor(color)), width=0, size=3) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="", y="Effect of a Black Request on Politicians' Response Rate", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=37)) +
  scale_size(range = c(7, 15)) +
  scale_y_continuous(limits=c(-.15, .15)) + 
  coord_flip() + 
  scale_colour_manual(values=color.names) + theme(legend.position="none") +
  annotate("text", x = 9.4 , y = -0.09, label="Discrimination Against Blacks", colour = "grey60", size=6, fontface="bold") +
  annotate("text", x = 9.4 , y = 0.09, label="Discrimination Against Whites", colour = "grey60", size=6, fontface="bold") 


plot1

ggsave(plot1, file="meta_analysis_elected_officials.png", width=10, height=6, scale=2)


##### FIGURE S2: Email Coverage by State

rules<-read.csv("emailcoverageclean.csv")

plot2<-ggplot(rules, aes(state, Email.Coverage))  + 
  geom_point(size=12) +  theme_bw() +   
  geom_segment(aes(x = state, y = 0, xend = state , yend = Email.Coverage), color = "black", size=3) +
  labs(x="", y="Email Coverage in Acxiom Files", title="") +
  theme(text = element_text(size=24)) + 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), axis.line = element_line(colour = "black"))+
  scale_y_continuous(limits=c(0, 50)) + 
  geom_hline(aes(yintercept=39.948494), colour="blue", linetype="dashed", size=2, alpha=0.5) 

plot2
ggsave(plot2, file="email_coverage.pdf", width=17, height=3, scale=2)

##### FIGURE S3, top: Sample Size by State (Public)

rules<-read.csv("samplesize.csv")

plot2<-ggplot(rules, aes(state, N))  + 
  geom_point(size=12) +  theme_bw() +   
  geom_segment(aes(x = state, y = 0, xend = state , yend = N), color = "black", size=3) +
  labs(x="", y="Sample Size by State (Public)", title="") +
  theme(text = element_text(size=24)) + 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), axis.line = element_line(colour = "black"))+
  scale_y_continuous(limits=c(0, 11000))
plot2
ggsave(plot2, file="sample_size_public.pdf", width=17, height=3, scale=2)


##### FIGURE S3, bottom: Sample Size by State (Elected)

rules<-read.csv("samplesizeelected.csv")

plot2<-ggplot(rules, aes(state, N))  + 
  geom_point(size=12) +  theme_bw() +   
  geom_segment(aes(x = state, y = 0, xend = state , yend = N), color = "black", size=3) +
  labs(x="", y="Sample Size by State (Elected)", title="") +
  theme(text = element_text(size=24)) + 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), axis.line = element_line(colour = "black"))+
  scale_y_continuous(limits=c(0, 5100))
plot2
ggsave(plot2, file="sample_size_elected.pdf", width=17, height=3, scale=2)

###### FIGURE S4/S5: Replicated and Reproduced from Crabtree (2019)

###### FIGURE S6: Effects by Names Held Out Iteratively, Jacknife (Public)
diffdiffall<-read.dta("jacknife names cleaned.dta")
attach(diffdiffall) 

color.names <- c("black", "grey50")

plot1<-ggplot(diffdiffall, aes(y=coef_base,  x=reorder(Name, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, aes(colour=white), size=12) +
  geom_errorbar(aes(ymin=coef_base-1.96*stderr_base, ymax=coef_base+1.96*stderr_base, colour=white), width=0, size=2) +
  geom_errorbar(aes(ymin=coef_base-1.64*stderr_base, ymax=coef_base+1.64*stderr_base, colour=white), width=0, size=4) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="Name Left out of Estimation", y="Effect on Black Sender on Response Rate", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_y_continuous(limits=c(-.4, .4)) + 
  theme(text = element_text(size=22)) +
  coord_flip() + theme(legend.position="none") 


plot1
ggsave(plot1, file="jacknife_name_public.png", width=5, height=5, scale=2)

######## FIGURE S7: Effects by Names Held Out Iteratively, Jacknife (ELECTED)


diffdiffall<-read.dta("jacknife names elected cleaned.dta")
attach(diffdiffall) 

color.names <- c("black", "grey50")

plot1<-ggplot(diffdiffall, aes(y=coef_base,  x=reorder(Name, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, aes(colour=white), size=12) +
  geom_errorbar(aes(ymin=coef_base-1.96*stderr_base, ymax=coef_base+1.96*stderr_base, colour=white), width=0, size=2) +
  geom_errorbar(aes(ymin=coef_base-1.64*stderr_base, ymax=coef_base+1.64*stderr_base, colour=white), width=0, size=4) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="Name Left out of Estimation", y="Effect on Black Sender on Response Rate", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_y_continuous(limits=c(-.4, .4)) + 
  theme(text = element_text(size=22)) +
  coord_flip() + theme(legend.position="none") 


plot1
ggsave(plot1, file="jacknife_name_elected.png", width=5, height=5, scale=2)

################# FIGURE S8: Effects by Names Individually (Public)


diffdiffall<-read.dta("effects by names cleaned.dta")
attach(diffdiffall) 

color.names <- c("black", "grey50")

plot1<-ggplot(diffdiffall, aes(y=coef_base,  x=reorder(var, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, aes(colour=white), size=12) +
  geom_errorbar(aes(ymin=coef_base-1.96*stderr_base, ymax=coef_base+1.96*stderr_base, colour=white), width=0, size=2) +
  geom_errorbar(aes(ymin=coef_base-1.64*stderr_base, ymax=coef_base+1.64*stderr_base, colour=white), width=0, size=4) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="Effect of Name Relative to Black/White Condition Pooled", y="Effect on Response Rate", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_y_continuous(limits=c(-.4, .4)) + 
  theme(text = element_text(size=22)) +
  coord_flip() + theme(legend.position="none") 


plot1
ggsave(plot1, file="name_comparison_public.png", width=5, height=5, scale=2)

################# FIGURE S9: Effects by Names Individually (Elected)


diffdiffall<-read.dta("effects by names elected cleaned.dta")
attach(diffdiffall) 

color.names <- c("black", "grey50")

plot1<-ggplot(diffdiffall, aes(y=coef_base,  x=reorder(var, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, aes(colour=white), size=12) +
  geom_errorbar(aes(ymin=coef_base-1.96*stderr_base, ymax=coef_base+1.96*stderr_base, colour=white), width=0, size=2) +
  geom_errorbar(aes(ymin=coef_base-1.64*stderr_base, ymax=coef_base+1.64*stderr_base, colour=white), width=0, size=4) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="Effect of Name Relative to Black/White Condition Pooled", y="Effect on Response Rate", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_y_continuous(limits=c(-.4, .4)) + 
  theme(text = element_text(size=22)) +
  coord_flip() + theme(legend.position="none") 


plot1
ggsave(plot1, file="name_comparison_elected.png", width=5, height=5, scale=2)


################# FIGURE S10: Covariate Balance (Public)


diffdiffall<-read.dta("public covariate balance.dta")
attach(diffdiffall) 

plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(variable, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, colour="black", size=9) +
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr), colour="black", width=0, size=1) +
  geom_errorbar(aes(ymin=coef-1.64*stderr, ymax=coef+1.64*stderr), colour="black", width=0, size=2) +
  theme_bw() + theme(axis.line = element_line(colour = "black"),
                     panel.grid.major = element_blank(),
                     panel.grid.minor = element_blank(),
                     panel.border = element_blank(),
                     panel.background = element_blank()) +
  labs(x="", y="Effect on Pre-Treatment Variable", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_y_continuous(limits=c(-.01, .01)) + 
  theme(text = element_text(size=28)) + theme(legend.position="none") +
  scale_size(range = c(4, 12)) +
  coord_flip() +
  labs(size = "Sample Size") 

plot1
ggsave(plot1, file="covariate_balance_public.pdf", width=5, height=11, scale=2)

################# FIGURE S11: Covariate Balance (Elected)


diffdiffall<-read.dta("elected covariate balance.dta")
attach(diffdiffall) 

plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(variable, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, colour="black", size=9) +
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr), colour="black", width=0, size=1) +
  geom_errorbar(aes(ymin=coef-1.64*stderr, ymax=coef+1.64*stderr), colour="black", width=0, size=2) +
  theme_bw() + theme(axis.line = element_line(colour = "black"),
                     panel.grid.major = element_blank(),
                     panel.grid.minor = element_blank(),
                     panel.border = element_blank(),
                     panel.background = element_blank()) +
  labs(x="", y="Effect on Pre-Treatment Variable", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_y_continuous(limits=c(-.01, .01)) + 
  theme(text = element_text(size=28)) + theme(legend.position="none") +
  scale_size(range = c(4, 12)) +
  coord_flip() +
  labs(size = "Sample Size") 

plot1
ggsave(plot1, file="covariate_balance_elected.pdf", width=5, height=11, scale=2)


#################  FIGURE S12: Covariate Balance (Pooled)


diffdiffall<-read.dta("pooled covariate balance.dta")
attach(diffdiffall) 

plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(variable, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, colour="black", size=9) +
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr), colour="black", width=0, size=1) +
  geom_errorbar(aes(ymin=coef-1.64*stderr, ymax=coef+1.64*stderr), colour="black", width=0, size=2) +
  theme_bw() + theme(axis.line = element_line(colour = "black"),
                     panel.grid.major = element_blank(),
                     panel.grid.minor = element_blank(),
                     panel.border = element_blank(),
                     panel.background = element_blank()) +
  labs(x="", y="Effect on Pre-Treatment Variable", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_y_continuous(limits=c(-.01, .01)) + 
  theme(text = element_text(size=28)) + theme(legend.position="none") +
  scale_size(range = c(4, 12)) +
  coord_flip() +
  labs(size = "Sample Size") 

plot1
ggsave(plot1, file="covariate_balance_pooled.pdf", width=5, height=11, scale=2)


##### FIGURE S13: Predictors of Difference Between Public and Elected OFficials 

rules<-read.csv("correlations.csv")

plot2<-ggplot(rules, aes(y=variable, x=corr)) +
  geom_vline(aes(xintercept=0), colour="#990000", linetype="dashed", size=1)  + 
  geom_point(size=12) +  theme_bw() +   
  geom_segment(aes(x = 0, y = variable, xend = corr , yend = variable), color = "black", size=3) +
  labs(x="Correlation Coefficient (Pearson R); Discrimination Against Blacks=Negative", y="Variables", title="") +
  theme(text = element_text(size=22)) + 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), axis.line = element_line(colour = "black")) +
  scale_x_continuous(limits=c(-1, 1)) 

plot2
ggsave(plot2, file="correlations_difference_public_elected.pdf", width=8, height=15, scale=2)


##### FIGURE S14: Predictors of Public Discrimination

rules<-read.csv("correlations public.csv")

plot2<-ggplot(rules, aes(y=variable, x=corr)) +
  geom_vline(aes(xintercept=0), colour="#990000", linetype="dashed", size=1)  + 
  geom_point(size=12) +  theme_bw() +   
  geom_segment(aes(x = 0, y = variable, xend = corr , yend = variable), color = "black", size=3) +
  labs(x="Correlation Coefficient (Pearson R); Discrimination Against Blacks=Negative", y="Variables", title="") +
  theme(text = element_text(size=22)) + 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), axis.line = element_line(colour = "black")) +
  scale_x_continuous(limits=c(-1, 1)) 

plot2
ggsave(plot2, file="correlations_public.pdf", width=8, height=15, scale=2)

##### FIGURE S15: Predictors of Elected Discrimination

rules<-read.csv("correlations elected.csv")

plot2<-ggplot(rules, aes(y=variable, x=corr)) +
  geom_vline(aes(xintercept=0), colour="#990000", linetype="dashed", size=1)  + 
  geom_point(size=12) +  theme_bw() +   
  geom_segment(aes(x = 0, y = variable, xend = corr , yend = variable), color = "black", size=3) +
  labs(x="Correlation Coefficient (Pearson R); Discrimination Against Blacks=Negative", y="Variables", title="") +
  theme(text = element_text(size=22)) + 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), axis.line = element_line(colour = "black")) +
  scale_x_continuous(limits=c(-1, 1)) 

plot2
ggsave(plot2, file="correlations_elected.pdf", width=8, height=15, scale=2)


########## FIGURE S16: Survey Completion as a DV


diffdiffall<-read.dta("effects_on_survey_completion_public_elected_cleaned.dta")
attach(diffdiffall) 

color.names <- c("#1b7837", "#762a83")

plot1<-ggplot(diffdiffall, aes(y=coef_base,  x=reorder(group, model_num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, aes(colour=group), size=12) +
  geom_errorbar(aes(ymin=coef_base-1.96*stderr_base, ymax=coef_base+1.96*stderr_base, colour=group), width=0, size=2) +
  geom_errorbar(aes(ymin=coef_base-1.64*stderr_base, ymax=coef_base+1.64*stderr_base, colour=group), width=0, size=4) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="", y="Effect of a Black Request on Survey Completion", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_y_continuous(limits=c(-.25, .25)) + 
  theme(text = element_text(size=22)) +
  coord_flip() + theme(legend.position="none") +
  scale_colour_manual(values=color.names) +
  annotate("text", x = 2.4 , y = -0.13, label="Discrimination Against Blacks", colour = "grey60", size=6, fontface="bold") +
  annotate("text", x = 2.4 , y = 0.13, label="Discrimination Against Whites", colour = "grey60", size=6, fontface="bold") 


plot1
ggsave(plot1, file="main_effect_survey_completion.png", width=5, height=3, scale=2)


################# FIGURE S17: Population Weights


diffdiffall<-read.dta("population_weights.dta")
attach(diffdiffall) 


plot1<-ggplot(diffdiffall, aes(y=coef_base,  x=reorder(subgroup, model_num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, colour="blue", size=12, position = pd) +
  geom_errorbar(aes(ymin=coef_base-1.96*stderr_base, ymax=coef_base+1.96*stderr_base), colour="blue", width=0, size=2, position = pd) +
  geom_errorbar(aes(ymin=coef_base-1.64*stderr_base, ymax=coef_base+1.64*stderr_base), colour="blue", width=0, size=4, position = pd) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="", y="Discriminatory Effects with Population Weights", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_y_continuous(limits=c(-.65, .65)) + 
  theme(text = element_text(size=22)) +
  coord_flip() + theme(legend.position="none") 


plot1
ggsave(plot1, file="population_weights.png", width=5, height=3, scale=2)


################# FIGURE S18, left: Coefficient Distribution

all3<-read.dta("interaction discrimination by state.dta")

attach(all3) 

plot1<- ggplot(all3, aes(coef)) +
  geom_density(alpha = 0.5, fill = "orange", colour = "orange", ) + 
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="State by State Differences in Public and Elected Official Discrimination Levels", y="Density", title="") +
  theme(text = element_text(size=24)) + 
  theme(legend.position="none") +
  geom_vline(aes(xintercept=0), colour="#990000", linetype="dashed", size=2) +
  labs(caption = "Lower = Elected Officials Discriminate More \n Higher = Public Discriminate More") 


plot1


ggsave(plot1, file="interaction_coef_dist.pdf", width=8, height=6, scale=2)

################# FIGURE S18, right: T-Stat Distribution

all3<-read.dta("interaction discrimination by state.dta")

attach(all3) 

plot1<- ggplot(all3, aes(t_stat)) +
  geom_density(alpha = 0.5, fill = "blue", colour = "blue") + 
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="T-Statistics", y="Density", title="") +
  theme(text = element_text(size=32)) + 
  scale_x_continuous(limits=c(-3.6, 3.6)) + theme(legend.position="none") +
  geom_vline(aes(xintercept=1.96), colour="#990000", linetype="dashed", size=2) +
  geom_vline(aes(xintercept=-1.96), colour="#990000", linetype="dashed", size=2) +
  geom_vline(aes(xintercept=0), colour="grey", linetype="dashed", size=2) +
  labs(caption = "Lower = Elected Officials Discriminate More \n Higher = Public Discriminate More") 


plot1

ggsave(plot1, file="interaction_pval_dist.pdf", width=8, height=6, scale=2)  


################# Figure S19: Main Effects (Public and Elected Officials)--Block FEs (south)

diffdiffall<-read.dta("overall_effects_concordance_block_vars_south.dta")
attach(diffdiffall) 

color.names <- c("#1b7837", "#762a83")

plot1<-ggplot(diffdiffall, aes(y=coef_base,  x=reorder(group, model_num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, aes(colour=group), size=12) +
  geom_errorbar(aes(ymin=coef_base-1.96*stderr_base, ymax=coef_base+1.96*stderr_base, colour=group), width=0, size=2) +
  geom_errorbar(aes(ymin=coef_base-1.64*stderr_base, ymax=coef_base+1.64*stderr_base, colour=group), width=0, size=4) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="", y="Effect of a Black Request on Response Rate", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_y_continuous(limits=c(-.25, .25)) + 
  theme(text = element_text(size=22)) +
  coord_flip() + theme(legend.position="none") +
  scale_colour_manual(values=color.names) +
  annotate("text", x = 2.4 , y = -0.13, label="Discrimination Against Blacks", colour = "grey60", size=6, fontface="bold") +
  annotate("text", x = 2.4 , y = 0.13, label="Discrimination Against Whites", colour = "grey60", size=6, fontface="bold") 

plot1
ggsave(plot1, file="main_effect_block_fe_south.png", width=5, height=3, scale=2)

################# FIGURE S20: Main Effects (Public and Elected Officials)--Block FEs (state)

diffdiffall<-read.dta("overall_effects_concordance_block_vars.dta")
attach(diffdiffall) 

color.names <- c("#1b7837", "#762a83")

plot1<-ggplot(diffdiffall, aes(y=coef_base,  x=reorder(group, model_num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, aes(colour=group), size=12) +
  geom_errorbar(aes(ymin=coef_base-1.96*stderr_base, ymax=coef_base+1.96*stderr_base, colour=group), width=0, size=2) +
  geom_errorbar(aes(ymin=coef_base-1.64*stderr_base, ymax=coef_base+1.64*stderr_base, colour=group), width=0, size=4) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="", y="Effect of a Black Request on Response Rate", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_y_continuous(limits=c(-.25, .25)) + 
  theme(text = element_text(size=22)) +
  coord_flip() + theme(legend.position="none") +
  scale_colour_manual(values=color.names) +
  annotate("text", x = 2.4 , y = -0.13, label="Discrimination Against Blacks", colour = "grey60", size=6, fontface="bold") +
  annotate("text", x = 2.4 , y = 0.13, label="Discrimination Against Whites", colour = "grey60", size=6, fontface="bold") 


plot1
ggsave(plot1, file="main_effect_block_fe.png", width=5, height=3, scale=2)


########## FIGURE S21: Individual Dot Plot (Public Just ignoring blacks): we cannot share the data for Figure S21/S22 in the Supporting Information, because it includes lat/long files. As per our data availability statement provided to the journal at original submission, we cannot share identifying information.
#us_states <- map_data("state")

#state_full2<-read.dta("") # data not included due to the inclusion of identifying information (i.e. lat/long codes)

#p <- ggplot(data = us_states,
#            mapping = aes(x = long, y = lat, group = group)) 

#p1 <- p + geom_polygon(colour = "grey90", fill="grey60", size = 0.05) +  
#  coord_map(projection = "albers", lat0 = 39, lat1 = 45) + 
#  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
#        panel.background = element_blank(), axis.line = element_line(colour = "grey40")) + theme_void()  +
#  guides(fill=guide_legend(title=""))  +
#  theme(text = element_text(size=30)) +
#  scale_x_continuous(expand = c(0, 0)) +
#  scale_y_continuous(expand = c(0, 0)) 

#p2 <- p1 + geom_count(data=state_full, aes(x = registrationaddresslongitude1, y = registrationaddresslatitude1, group="none"), 
 #                     size=6, alpha=0.35, colour="#762a83") 

#p3 <- p2 + theme(legend.position="top") +   
#  annotate("text", x = -73.3 , y = 29, label="Responded to white, but not black sender", colour = "#762a83", size=11, fontface="bold")  


#p3

#ggsave(p3, file="public_dot_map_just_black_discrim.pdf", width=19, height=10, scale=2, dpi=300)


###############  FIGURE S22: Individual Dot Plot (Public Just ignoring whites): we cannot share the data for Figure S21/S22 in the Supporting Information, because it includes lat/long files. As per our data availability statement provided to the journal at original submission, we cannot share identifying information.
#us_states <- map_data("state")

#state_full2<-read.dta("") # data not included due to the inclusion of identifying information (i.e. lat/long codes)

#p <- ggplot(data = us_states,
#            mapping = aes(x = long, y = lat, group = group)) 

#p1 <- p + geom_polygon(colour = "grey90", fill="grey60", size = 0.05) +  
#  coord_map(projection = "albers", lat0 = 39, lat1 = 45) + 
#  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
#        panel.background = element_blank(), axis.line = element_line(colour = "grey40")) + theme_void()  +
#  guides(fill=guide_legend(title=""))  +
#  theme(text = element_text(size=30)) +
#  scale_x_continuous(expand = c(0, 0)) +
#  scale_y_continuous(expand = c(0, 0)) 

#p2 <- p1 +  geom_count(data=state_full2, aes(x = registrationaddresslongitude1, y = registrationaddresslatitude1, group="none"), 
#                       size=6, alpha=0.25, colour="#1b7837")

#p3 <- p2 + theme(legend.position="top") +   
#  annotate("text", x = -73, y = 30, label="Responded to black, but not white sender", colour = "#1b7837", size=11, fontface="bold") 


#p3


#ggsave(p3, file="public_dot_map_just_white_discrim.pdf", width=19, height=10, scale=2, dpi=300)


################# FIGURE S23: Iteratively Leave Out (Public)


diffdiffall<-read.dta("iteratively_leave_state_out.dta")
attach(diffdiffall) 

plot1<-ggplot(diffdiffall, aes(y=coef_base,  x=state))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_errorbar(aes(ymin=coef_base-1.96*stderr_base, ymax=coef_base+1.96*stderr_base), colour="black", width=0, size=1) +
  geom_errorbar(aes(ymin=coef_base-1.64*stderr_base, ymax=coef_base+1.64*stderr_base), colour="black", width=0, size=2) +
  geom_point(data=diffdiffall, colour="black", size=11) +
  theme_bw() + theme(axis.line = element_line(colour = "black"),
                     panel.grid.major = element_blank(),
                     panel.grid.minor = element_blank(),
                     panel.border = element_blank(),
                     panel.background = element_blank()) +
  labs(x="Left Out State", y="Effect of Black Sender on Response Rates", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_y_continuous(limits=c(-.25, .25)) + 
  theme(text = element_text(size=28)) + theme(legend.position="none") +
  scale_size(range = c(4, 12)) +
  coord_flip() +
  labs(size = "Sample Size") 

plot1
ggsave(plot1, file="iteratively_leave_out_public.pdf", width=5, height=11, scale=2)

################# FIGURE S24: Iteratively Leave Out (Elected)


diffdiffall<-read.dta("iteratively_leave_state_out_elected.dta")
attach(diffdiffall) 

plot1<-ggplot(diffdiffall, aes(y=coef_base,  x=state))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, colour="black", size=11) +
  geom_errorbar(aes(ymin=coef_base-1.96*stderr_base, ymax=coef_base+1.96*stderr_base), colour="black", width=0, size=1) +
  geom_errorbar(aes(ymin=coef_base-1.64*stderr_base, ymax=coef_base+1.64*stderr_base), colour="black", width=0, size=2) +
  theme_bw() + theme(axis.line = element_line(colour = "black"),
                     panel.grid.major = element_blank(),
                     panel.grid.minor = element_blank(),
                     panel.border = element_blank(),
                     panel.background = element_blank()) +
  labs(x="Left Out State", y="Effect of Black Sender on Response Rates", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_y_continuous(limits=c(-.25, .25)) + 
  theme(text = element_text(size=28)) + theme(legend.position="none") +
  scale_size(range = c(4, 12)) +
  coord_flip() +
  labs(size = "Sample Size") 

plot1
ggsave(plot1, file="iteratively_leave_out_elected.pdf", width=5, height=11, scale=2)

################# FIGURE S25: Iteratively Leave Out (Interaction)


diffdiffall<-read.dta("iteratively_leave_state_out_interaction.dta")
attach(diffdiffall) 

plot1<-ggplot(diffdiffall, aes(y=coef_base,  x=state))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, colour="black", size=11) +
  geom_errorbar(aes(ymin=coef_base-1.96*stderr_base, ymax=coef_base+1.96*stderr_base), colour="black", width=0, size=1) +
  geom_errorbar(aes(ymin=coef_base-1.64*stderr_base, ymax=coef_base+1.64*stderr_base), colour="black", width=0, size=2) +
  theme_bw() + theme(axis.line = element_line(colour = "black"),
                     panel.grid.major = element_blank(),
                     panel.grid.minor = element_blank(),
                     panel.border = element_blank(),
                     panel.background = element_blank()) +
  labs(x="Left Out State", y="Effect of Black Sender on Response Rates", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_y_continuous(limits=c(-.25, .25)) + 
  theme(text = element_text(size=28)) + theme(legend.position="none") +
  scale_size(range = c(4, 12)) +
  coord_flip() +
  labs(size = "Sample Size") 

plot1
ggsave(plot1, file="iteratively_leave_out_interaction.pdf", width=5, height=11, scale=2)

################# FIGURE S26: Elected Official Effects (Race of the Recipient FOR CONCORDANCE)


diffdiffall<-read.dta("overall_effects_by_recipient_race_elected_officials_old.dta")
attach(diffdiffall) 

plot1<-ggplot(diffdiffall, aes(y=coef_base,  x=reorder(group, model_num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, colour="black", aes(size=N)) +
  geom_errorbar(aes(ymin=coef_base-1.96*stderr_base, ymax=coef_base+1.96*stderr_base), colour="black", width=0, size=1) +
  geom_errorbar(aes(ymin=coef_base-1.64*stderr_base, ymax=coef_base+1.64*stderr_base), colour="black", width=0, size=2) +
  theme_bw() + theme(axis.line = element_line(colour = "black"),
                     panel.grid.major = element_blank(),
                     panel.grid.minor = element_blank(),
                     panel.border = element_blank(),
                     panel.background = element_blank()) +
  labs(x="Recipient Race/Ethnicity", y="Effect of a Black Request on Response Rate", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=15)) + theme(legend.position="none") +
  scale_size(range = c(4, 12)) +
  coord_flip() +
  labs(size = "Sample Size") 

plot1
ggsave(plot1, file="elected_official_effect_by_recipient_race_for_concordance.png", width=4, height=4, scale=2)

################# FIGURE S27: By Political Party and Race (Voters)


diffdiffall<-read.dta("race_by_party.dta")
attach(diffdiffall) 

color.names <- c("blue", "darkgreen", "red")

pd <- position_dodge(width=0.62)  

plot1<-ggplot(diffdiffall, aes(y=coef_base,  x=reorder(subgroup, model_num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, aes(colour=subgroup), size=12, position = pd) +
  geom_errorbar(aes(ymin=coef_base-1.96*stderr_base, ymax=coef_base+1.96*stderr_base, colour=subgroup), width=0, size=2, position = pd) +
  geom_errorbar(aes(ymin=coef_base-1.64*stderr_base, ymax=coef_base+1.64*stderr_base, colour=subgroup), width=0, size=4, position = pd) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="", y="Difference in Discriminatory Effects by Political Party", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=22)) +
  scale_y_continuous(limits=c(-.55, .55)) + 
  coord_flip() + theme(legend.position="none") +
  scale_colour_manual(values=color.names) +
  annotate("text", x = 3.4 , y = -0.28, label="Whites in Party Discriminate more than Blacks", colour = "grey60", size=4, fontface="bold") +
  annotate("text", x = 3.4 , y = 0.28, label="Whites in Party Discriminate less than Blacks", colour = "grey60", size=4, fontface="bold") 

plot1
ggsave(plot1, file="effects_by_party_race.png", width=5, height=3, scale=2)

#################  FIGURE S28: Effects by South (FOR CONCORDANCE)


diffdiffall<-read.dta("effects by south.dta")
attach(diffdiffall) 

plot1<-ggplot(diffdiffall, aes(y=coef_base,  x=group))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, colour="blue", aes(size=N)) +
  geom_errorbar(aes(ymin=coef_base-1.96*stderr_base, ymax=coef_base+1.96*stderr_base), colour="blue", width=0, size=1) +
  geom_errorbar(aes(ymin=coef_base-1.64*stderr_base, ymax=coef_base+1.64*stderr_base), colour="blue", width=0, size=2) +
  theme_bw() + theme(axis.line = element_line(colour = "black"),
                     panel.grid.major = element_blank(),
                     panel.grid.minor = element_blank(),
                     panel.border = element_blank(),
                     panel.background = element_blank()) +
  labs(x="", y="Effect of a Black Request by South", title="") +
  scale_y_continuous(limits=c(-.25, .25)) + 
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=15)) + theme(legend.position="none") +
  scale_size(range = c(4, 12)) +
  coord_flip() +
  labs(size = "Sample Size") 

plot1
ggsave(plot1, file="effect_by_south_for_concordance.pdf", width=4, height=2, scale=2)


######### FIGURE S29: Public + Elected Officials

all3<-read.dta("interaction discrimination by state.dta")

attach(all3) 

pd <- position_dodge(width=0.62)  

color.names <- c("#000000", "#bdbdbd")

plot1<-ggplot(all3, aes(y=coef,  x=interaction))+ 
  geom_hline(aes(yintercept=0), colour="#990000", linetype="dashed", size=2) +
  geom_point(data=all3, size=8,  aes(colour = factor(interaction)), position = pd) +
  facet_wrap(~state_abbrev, nrow=10)  +
  geom_errorbar(data=all3, aes(ymin=coef-1.96*se, ymax= coef+1.96*se, colour = factor(interaction)), position = pd, width=0, size=1) +
  geom_errorbar(data=all3, aes(ymin=coef-1.64*se, ymax= coef+1.64*se, colour = factor(interaction)), position = pd, width=0, size=3)+
  scale_colour_manual(values=color.names) + theme_bw() + theme(panel.grid.major = element_blank(), 
                                                               panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(legend.title = element_blank()) +
  theme(legend.position="none", legend.direction="horizontal") +
  labs(x="", y="Difference in Discrimination Effect Between Public and Elected Officials", title="") +
  theme(text = element_text(size=30)) + 
  theme(axis.text.x = element_text(angle=90, hjust = 1)) +
  coord_flip() +
  theme(axis.title.y=element_blank(),
        axis.text.y=element_blank(),
        axis.ticks.y=element_blank()) +
  labs(caption = "Lower = Elected Officials Discriminate More \n Higher = Public Discriminate More") 


plot1 
ggsave(plot1, file="interaction_effects.pdf", width=16, height=8, scale=2)


################# FIGURE S30, LEFT: Effects by State (Public)--NO Individual FE Marginal Effects



diffdiffall<-read.dta("public discrimination by state.dta")
attach(diffdiffall) 

plot1<-ggplot(diffdiffall, aes(y=coef_base, x=reorder(state_abbrev, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_errorbar(aes(ymin=coef_base-1.96*se_base, ymax=coef_base+1.96*se_base), colour="grey50", width=0, size=1) +
  geom_errorbar(aes(ymin=coef_base-1.64*se_base, ymax=coef_base+1.64*se_base), colour="grey50", width=0, size=2) +
  geom_point(data=diffdiffall, colour="black", size=11) +
  theme_bw() + theme(axis.line = element_line(colour = "black"),
                     panel.grid.major = element_blank(),
                     panel.grid.minor = element_blank(),
                     panel.border = element_blank(),
                     panel.background = element_blank()) +
  labs(x="State", y="Effect of Black Sender on Response Rates in a Given State", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_y_continuous(limits=c(-1, 1)) + 
  theme(text = element_text(size=28)) + theme(legend.position="none") +
  scale_size(range = c(4, 12)) +
  coord_flip() +
  labs(size = "Sample Size") 

plot1
ggsave(plot1, file="effects_by_state_public.pdf", width=6, height=11, scale=2)

################# FIGURE S30, RIGHT: Effects by State (Public)-- Individual FE Effects Themselves



diffdiffall<-read.dta("public_state_estimates.dta")
attach(diffdiffall) 

plot1<-ggplot(diffdiffall, aes(y=coef_base, x=reorder(state, num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_errorbar(aes(ymin=coef_base-1.96*se_base, ymax=coef_base+1.96*se_base), colour="grey50", width=0, size=1) +
  geom_errorbar(aes(ymin=coef_base-1.64*se_base, ymax=coef_base+1.64*se_base), colour="grey50", width=0, size=2) +
  geom_point(data=diffdiffall, colour="black", size=11) +
  theme_bw() + theme(axis.line = element_line(colour = "black"),
                     panel.grid.major = element_blank(),
                     panel.grid.minor = element_blank(),
                     panel.border = element_blank(),
                     panel.background = element_blank()) +
  labs(x="State", y="Effect of Black Sender on Response Rates in a Given State", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_y_continuous(limits=c(-1, 1)) + 
  theme(text = element_text(size=28)) + theme(legend.position="none") +
  scale_size(range = c(4, 12)) +
  coord_flip() +
  labs(size = "Sample Size") 

plot1
ggsave(plot1, file="effects_by_state_public_individual_fe.pdf", width=6, height=11, scale=2)

################# FIGURE S31: Interaction Reported vs. Modeled Race


diffdiffall<-read.dta("reporting_states.dta")
attach(diffdiffall) 

color.names <- c("black", "grey")

pd <- position_dodge(width=0.62)  

plot1<-ggplot(diffdiffall, aes(y=coef,  x=reorder(subgroup, model_num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, aes(colour=dv), size=12, position = pd) +
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour=dv), width=0, size=2, position = pd) +
  geom_errorbar(aes(ymin=coef-1.64*stderr, ymax=coef+1.64*stderr, colour=dv), width=0, size=4, position = pd) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="", y="Difference in Discriminatory Effects by Reported Race States", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_y_continuous(limits=c(-.03, .03)) + 
  theme(text = element_text(size=22)) +
  coord_flip() + theme(legend.position="bottom") +
  scale_colour_manual(values=color.names) 


plot1
ggsave(plot1, file="differential_effect_by_reported_modeled_race.png", width=6, height=7, scale=2)


################# FIGURE S32: By Age (Voters)



diffdiffall<-read.dta("results_by_age.dta")
attach(diffdiffall) 

color.names <- c("black", "grey30", "grey60")

pd <- position_dodge(width=0.62)  

plot1<-ggplot(diffdiffall, aes(y=coef_base,  x=reorder(subgroup, model_num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, aes(colour=subgroup), size=12, position = pd) +
  geom_errorbar(aes(ymin=coef_base-1.96*stderr_base, ymax=coef_base+1.96*stderr_base, colour=subgroup), width=0, size=2, position = pd) +
  geom_errorbar(aes(ymin=coef_base-1.64*stderr_base, ymax=coef_base+1.64*stderr_base, colour=subgroup), width=0, size=4, position = pd) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="", y="Difference in Discriminatory Effects by Age", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=22)) +
  scale_y_continuous(limits=c(-.3, .3)) + 
  coord_flip() + theme(legend.position="none") +
  scale_colour_manual(values=color.names) 
plot1
ggsave(plot1, file="effects_by_age.png", width=5, height=3, scale=2)


################# FIGURE S33: Elected Official + Public Pooled Effects (Race of the Recipient FOR CONCORDANCE)


diffdiffall<-read.dta("pooled_effects.dta")
attach(diffdiffall) 

plot1<-ggplot(diffdiffall, aes(y=coef_base,  x=reorder(race, model_num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, colour="blue", aes(size=N)) +
  geom_errorbar(aes(ymin=coef_base-1.96*stderr_base, ymax=coef_base+1.96*stderr_base), colour="blue", width=0, size=1) +
  geom_errorbar(aes(ymin=coef_base-1.64*stderr_base, ymax=coef_base+1.64*stderr_base), colour="blue", width=0, size=2) +
  theme_bw() + theme(axis.line = element_line(colour = "black"),
                     panel.grid.major = element_blank(),
                     panel.grid.minor = element_blank(),
                     panel.border = element_blank(),
                     panel.background = element_blank()) +
  labs(x="Recipient Race/Ethnicity", y="Effect of a Black Request on Response Rate", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=15)) + theme(legend.position="none") +
  scale_size(range = c(4, 12)) +
  coord_flip() +
  labs(size = "Sample Size") 

plot1
ggsave(plot1, file="pooled_by_recipient_race_for_concordance.png", width=4, height=4, scale=2)

#################  FIGURE S34: Effects by Gender of the Recipient (FOR CONCORDANCE)


diffdiffall<-read.dta("effects by gender.dta")
attach(diffdiffall) 

plot1<-ggplot(diffdiffall, aes(y=coef_base,  x=group))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, colour="blue", aes(size=N)) +
  geom_errorbar(aes(ymin=coef_base-1.96*stderr_base, ymax=coef_base+1.96*stderr_base), colour="blue", width=0, size=1) +
  geom_errorbar(aes(ymin=coef_base-1.64*stderr_base, ymax=coef_base+1.64*stderr_base), colour="blue", width=0, size=2) +
  theme_bw() + theme(axis.line = element_line(colour = "black"),
                     panel.grid.major = element_blank(),
                     panel.grid.minor = element_blank(),
                     panel.border = element_blank(),
                     panel.background = element_blank()) +
  labs(x="", y="Effect of a Black Request by Gender", title="") +
  scale_y_continuous(limits=c(-.25, .25)) + 
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=15)) + theme(legend.position="none") +
  scale_size(range = c(4, 12)) +
  coord_flip() +
  labs(size = "Sample Size") 

plot1
ggsave(plot1, file="effect_by_recipient_gender_for_concordance.pdf", width=4, height=2, scale=2)

################# FIGURE S35: By Name Familiarity (Voters)



diffdiffall<-read.dta("differential_effects_by_familiarity.dta")
attach(diffdiffall) 

color.names <- c("black", "grey60")

pd <- position_dodge(width=0.62)  

plot1<-ggplot(diffdiffall, aes(y=coef,  x=var))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, aes(colour=group), size=6, position = pd) +
  geom_errorbar(aes(ymin=coef-1.96*stderr, ymax=coef+1.96*stderr, colour=group), width=0, size=1, position = pd) +
  geom_errorbar(aes(ymin=coef-1.64*stderr, ymax=coef+1.64*stderr, colour=group), width=0, size=2, position = pd) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="", y="Difference in Discriminatory Effects by Treatment Name Familiarity", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  theme(text = element_text(size=16)) +
  scale_y_continuous(limits=c(-.015, .015)) + 
  coord_flip() + theme(legend.position="bottom") +
  scale_colour_manual(values=color.names) + theme(legend.title = element_blank())
plot1
ggsave(plot1, file="effects_by_familiarity.png", width=5, height=3, scale=2)

################# FIGURE S36, Interaction Survey Wave


diffdiffall<-read.dta("differential_effects_by_wave.dta")
attach(diffdiffall) 

color.names <- c("#1b7837", "#762a83", "#1b7837", "#762a83")

plot1<-ggplot(diffdiffall, aes(y=coef_base,  x=reorder(group, model_num)))+ 
  geom_hline(aes(yintercept=0), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, aes(colour=group), size=12) +
  geom_errorbar(aes(ymin=coef_base-1.96*stderr_base, ymax=coef_base+1.96*stderr_base, colour=group), width=0, size=2) +
  geom_errorbar(aes(ymin=coef_base-1.64*stderr_base, ymax=coef_base+1.64*stderr_base, colour=group), width=0, size=4) +
  theme_bw() + theme(panel.grid.major = element_blank(), 
                     panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  labs(x="", y="Difference between Wave 1 and Wave 2 Discriminatory Effects", title="") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_y_continuous(limits=c(-.45, .45)) + 
  theme(text = element_text(size=22)) +
  coord_flip() + theme(legend.position="none") +
  scale_colour_manual(values=color.names) 


plot1
ggsave(plot1, file="differential_effect_by_wave.png", width=7, height=3, scale=2)

######### FIGURE S37: CORRELATION HEATMAP

priority<-read.csv("Racial Animus by State.csv")
#priority<-read.csv("correlation_matrix_audit.csv")

head(priority)

priority$X <- priority$State <- priority$Abbreviation <- priority$Code <- priority$pop_covered <- NULL
colnames(priority)

priority = subset(priority, select = -c(hatecrimes10k,hatecrimes2015, hatecrimes2015by10k, hategroups) )

priority.cor <- cor(priority)
priority.cor

axislabels <- c("Racially Charged Search Rate",                
                "MrP Estimates",  
                "Racial Resentment Among Whites", 
                "Racial Resentment",  
                "Implicit Association Test",  
                "Hate Crimes")

axislabelsy <- c("Number of Hate Groups", 
                 "Racially Charged Search Rate",                 
                 "MrP Estimates", 
                 "Racial Resentment Among Whites",  
                 "Racial Resentment",  
                 "Implicit Association Test"
)

g <- ggcorrplot(priority.cor, hc.order = TRUE, type = "lower",
                outline.col = "white", lab = T, colors = c("#762a83", "#f7f7f7", "#1b7837"))

g1 <- g +  scale_x_discrete(labels= axislabels) + 
  theme(axis.text.x = element_text(angle = 90, hjust = 1)) +   
  scale_y_discrete(labels= axislabelsy)


g1

ggsave(g1, file="alternate_corrplot_pared.pdf", width=6, height=6, scale=2)


######### FIGURE S38:  STATE LEVEL MAPS

### Public -- Racial Resentment (Whites)
us_states <- map_data("state")



map2000<-read.dta("Racial Animus by State.dta")

state_full <- left_join(us_states, map2000, by = "region")

attach(map2000)

n=6
breaks = seq(min(whiteracialresentment), max(whiteracialresentment), length.out = n)

p <- ggplot(data = state_full,
            mapping = aes(x = long, y = lat,
                          fill = whiteracialresentment, group = group)) + scale_colour_gradient(low = "white", high = "black")

p1 <- p + geom_polygon(color = "gray90", size = 0.05) +  coord_map(projection = "albers", lat0 = 39, lat1 = 45) + 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), axis.line = element_line(colour = "black")) + theme_void() + theme(legend.position="bottom") +
  guides(fill=guide_legend(title=""))  +
  theme(text = element_text(size=30)) +
  scale_x_continuous(expand = c(0, 0)) +
  scale_y_continuous(expand = c(0, 0)) 

p2 <- p1 + scale_fill_gradient(low="white", high="black", 
                               breaks=breaks, labels = scales::number_format(accuracy = 0.01,
                                                                             decimal.mark = '.')) 

p2

ggsave(p2, file="public_by_state_racial_resentment.pdf", width=8, height=5, scale=2, dpi = 300)

### Public -- IAT
us_states <- map_data("state")



map2000<-read.dta("raceiatdat_state_just_white.dta")

state_full <- left_join(us_states, map2000, by = "region")

attach(map2000)
n=6
breaks = seq(min(implicit_white), max(implicit_white), length.out = n)

p <- ggplot(data = state_full,
            mapping = aes(x = long, y = lat,
                          fill = implicit_white, group = group)) + scale_colour_gradient(low = "white", high = "black")

p1 <- p + geom_polygon(color = "gray90", size = 0.05) +  coord_map(projection = "albers", lat0 = 39, lat1 = 45) + 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), axis.line = element_line(colour = "black")) + theme_void() + theme(legend.position="bottom") +
  guides(fill=guide_legend(title=""))  +
  theme(text = element_text(size=30)) +
  scale_x_continuous(expand = c(0, 0)) +
  scale_y_continuous(expand = c(0, 0)) 

p2 <- p1 + scale_fill_gradient(low="white", high="black",
                               breaks=breaks, labels = scales::number_format(accuracy = 0.01, decimal.mark = '.')) 

p2

ggsave(p2, file="public_by_state_iat.pdf", width=8, height=5, scale=2, dpi = 300)


### Public -- Search Rate
us_states <- map_data("state")



map2000<-read.dta("Racial Animus by State.dta")

state_full <- left_join(us_states, map2000, by = "region")

summary(map2000$raciallychargedsearchrate)

attach(map2000)
n=6
breaks = seq(min(raciallychargedsearchrate), max(raciallychargedsearchrate), length.out = n)


p <- ggplot(data = state_full,
            mapping = aes(x = long, y = lat,
                          fill = raciallychargedsearchrate, group = group)) + scale_colour_gradient(low = "white", high = "black")

p1 <- p + geom_polygon(color = "gray90", size = 0.05) +  coord_map(projection = "albers", lat0 = 39, lat1 = 45) + 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), axis.line = element_line(colour = "black")) + theme_void() + theme(legend.position="bottom") +
  guides(fill=guide_legend(title=""))  +
  theme(text = element_text(size=30)) +
  scale_x_continuous(expand = c(0, 0)) +
  scale_y_continuous(expand = c(0, 0)) 

p2 <- p1 + scale_fill_gradient(low="white", high="black",
                               breaks=breaks, labels = scales::number_format(accuracy = 1, decimal.mark = '.')) 

p2

ggsave(p2, file="public_by_state_raciallychargedsearchrate.pdf", width=8, height=5, scale=2, dpi = 300)

### Public -- Hate Crimes
us_states <- map_data("state")



map2000<-read.dta("Racial Animus by State.dta")

state_full <- left_join(us_states, map2000, by = "region")

attach(map2000)
n=6
breaks = seq(min(hatecrimes2015by10k), max(hatecrimes2015by10k), length.out = n)

p <- ggplot(data = state_full,
            mapping = aes(x = long, y = lat,
                          fill = hatecrimes2015by10k, group = group)) + scale_colour_gradient(low = "white", high = "black")

p1 <- p + geom_polygon(color = "gray90", size = 0.05) +  coord_map(projection = "albers", lat0 = 39, lat1 = 45) + 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), axis.line = element_line(colour = "black")) + theme_void() + theme(legend.position="bottom") +
  guides(fill=guide_legend(title=""))  +
  theme(text = element_text(size=30)) +
  scale_x_continuous(expand = c(0, 0)) +
  scale_y_continuous(expand = c(0, 0)) 

p2 <- p1 + scale_fill_gradient(low="white", high="black",
                               breaks=breaks, labels = scales::number_format(accuracy = 0.01, decimal.mark = '.')) 

p2

ggsave(p2, file="public_by_state_hatecrimes.pdf", width=8, height=5, scale=2, dpi = 300)

### Public -- Hate Groups
us_states <- map_data("state")



map2000<-read.dta("Racial Animus by State.dta")

state_full <- left_join(us_states, map2000, by = "region")

attach(map2000)
n=6
breaks = seq(min(hategroups), max(hategroups), length.out = n)

p <- ggplot(data = state_full,
            mapping = aes(x = long, y = lat,
                          fill = hategroups, group = group)) + scale_colour_gradient(low = "white", high = "black")

p1 <- p + geom_polygon(color = "gray90", size = 0.05) +  coord_map(projection = "albers", lat0 = 39, lat1 = 45) + 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), axis.line = element_line(colour = "black")) + theme_void() + theme(legend.position="bottom") +
  guides(fill=guide_legend(title=""))  +
  theme(text = element_text(size=30)) 


p2 <- p1 + scale_fill_gradient(low="white", high="black",
                               breaks=breaks, labels = scales::number_format(accuracy = 0.1, decimal.mark = '.')) +
  scale_x_continuous(expand = c(0, 0)) +
  scale_y_continuous(expand = c(0, 0)) 

p2

ggsave(p2, file="public_by_state_hategroups.pdf", width=8, height=5, scale=2, dpi = 300)


### Public -- MRP
us_states <- map_data("state")



map2000<-read.dta("Racial Animus by State.dta")

state_full <- left_join(us_states, map2000, by = "region")

attach(map2000)
n=6
breaks = seq(min(mrp), max(mrp), length.out = n)

p <- ggplot(data = state_full,
            mapping = aes(x = long, y = lat,
                          fill = mrp, group = group)) + scale_colour_gradient(low = "white", high = "black")

p1 <- p + geom_polygon(color = "gray90", size = 0.05) +  coord_map(projection = "albers", lat0 = 39, lat1 = 45) + 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), axis.line = element_line(colour = "black")) + theme_void() + theme(legend.position="bottom") +
  guides(fill=guide_legend(title=""))  +
  theme(text = element_text(size=30)) 


p2 <- p1 + scale_fill_gradient(low="white", high="black",
                               breaks=breaks, labels = scales::number_format(accuracy = 0.01, decimal.mark = '.')) +
  scale_x_continuous(expand = c(0, 0)) +
  scale_y_continuous(expand = c(0, 0)) 

p2

ggsave(p2, file="public_by_state_mrp.pdf", width=8, height=5, scale=2, dpi = 300)


### Public--Our Measure
us_states <- map_data("state")



map2000<-read.dta("public discrimination by state.dta")

state_full <- left_join(us_states, map2000, by = "region")

attach(map2000)
n=6
breaks = seq(min(coef), max(coef), length.out = n)

p <- ggplot(data = state_full,
            mapping = aes(x = long, y = lat,
                          fill = coef, group = group)) + scale_colour_gradient(low = "black", high = "white")

p1 <- p + geom_polygon(color = "gray90", size = 0.05) +  coord_map(projection = "albers", lat0 = 39, lat1 = 45) + 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), axis.line = element_line(colour = "black")) + theme_void() + theme(legend.position="bottom") +
  guides(fill=guide_legend(title=""))  +
  theme(text = element_text(size=30)) 

p2 <- p1 + scale_fill_gradient(low="grey10", high="grey50",
                               breaks=breaks, labels = scales::number_format(accuracy = 0.001, decimal.mark = '.')) +
  labs(caption = "Black = More Discrimination Towards Blacks") +
  scale_x_continuous(expand = c(0, 0)) +
  scale_y_continuous(expand = c(0, 0)) 

  p2

ggsave(p2, file="public_by_state.pdf", width=8, height=5, scale=2, dpi = 300)














